package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@SpringBootApplication
@Controller
public class DemoApplication {
    @RequestMapping("/login")
    public String login(Model model, String username, String password) {
        if (username.equals("123") && password.equals("123456")) {
            return "main.html";
        } else {
            model.addAttribute("msg", "错误:请检查账号密码");
            return "index.html";
        }
    }

    @RequestMapping("/joke")
    public String index(Model model) {
        System.out.println("ajax运行到这里");
        model.addAttribute("msg", "这是一个笑话界面");
        /* return "joke.html"; 利用ajax进行跳转到这里是不会执行的,window.location.href="" 在前端跳转*/
        return "joke.html";
    }

    @RequestMapping("/tojoke")
    public String tojoke() {
        return "joke.html";
    }

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}
